
package org.springblade.modules.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.app.entity.ProductOrder;
import org.springblade.modules.app.service.IProductOrderService;
import org.springframework.web.bind.annotation.*;

/**
 * 订单表 控制器
 *
 * @author BladeX
 * @since 2020-08-20
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-app/productorder")
@Api(value = "订单表", tags = "订单表接口")
public class ProductOrderController extends BladeController {

    private final IProductOrderService productOrderService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入productOrder")
    public R<ProductOrder> detail(ProductOrder productOrder) {
        ProductOrder detail = productOrderService.getOne(Condition.getQueryWrapper(productOrder));
        return R.data(detail);
    }

    /**
     * 分页 订单表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入productOrder")
    public R<IPage<ProductOrder>> list(Page page, ProductOrder productOrder) {
        LambdaQueryWrapper<ProductOrder> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.orderByDesc(ProductOrder::getCtime);
        IPage<ProductOrder> pages = productOrderService.page(page, queryWrapper);
        return R.data(pages);
    }

    /**
     * 自定义分页 订单表
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入productOrder")
    public R<IPage<ProductOrder>> page(Page page, ProductOrder productOrder) {
        LambdaQueryWrapper<ProductOrder> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.orderByDesc(ProductOrder::getCtime);
        IPage<ProductOrder> pages = productOrderService.page(page, queryWrapper);
        return R.data(pages);
    }

    /**
     * 新增 订单表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入productOrder")
    public R save(@RequestBody ProductOrder productOrder) {
        return R.status(productOrderService.save(productOrder));
    }

    /**
     * 修改 订单表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入productOrder")
    public R update(@RequestBody ProductOrder productOrder) {
        return R.status(productOrderService.updateById(productOrder));
    }

    /**
     * 新增或修改 订单表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入productOrder")
    public R submit(@RequestBody ProductOrder productOrder) {
        return R.status(productOrderService.saveOrUpdate(productOrder));
    }


    /**
     * 删除 订单表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(productOrderService.removeByIds(Func.toLongList(ids)));
    }


}
